{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c8221b75",
   "metadata": {},
   "outputs": [],
   "source": [
    "import turtle\n",
    "# 返回或设置画笔颜色和填充颜色。\n",
    "# color(colorstring1, colorstring2), color((r1,g1,b1), (r2,g2,b2))\n",
    "# 相当于 pencolor(colorstring1) 加 fillcolor(colorstring2)，使用其他输入格式的方法也与之类似。\n",
    "turtle.color('red', 'yellow')\n",
    "# 在绘制要填充的形状之前调用。\n",
    "turtle.begin_fill()\n",
    "while True:\n",
    "    turtle.forward(200) # 海龟前进 distance 指定的距离，方向为海龟的朝向。\n",
    "    # 海龟左转 angle 个单位。(单位默认为角度，但可通过 degrees() 和 radians() 函数改变设置。) \n",
    "    # 角度的正负由海龟模式确定，参见 mode()\n",
    "    turtle.left(170)\n",
    "    # 返回海龟当前的坐标 (x,y)\n",
    "    if abs(turtle.pos()) < 1:\n",
    "        break\n",
    "# 填充上次调用 begin_fill() 之后绘制的形状。\n",
    "turtle.end_fill()\n",
    "# 开始事件循环 - 调用 Tkinter 的 mainloop 函数。必须作为一个海龟绘图程序的结束语句。\n",
    "# 如果一个脚本是在以 -n 模式 (无子进程) 启动的 IDLE 中运行时 不可 使用 - 用于实现海龟绘图的交互功能。\n",
    "turtle.done()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fe9772a7",
   "metadata": {},
   "source": [
    "[turtle --- 海龟绘图](https://docs.python.org/zh-cn/3/library/turtle.html)\n",
    "\n",
    "海龟绘图很适合用来引导孩子学习编程。 最初来自于 Wally Feurzeig, Seymour Papert 和 Cynthia Solomon 于 1967 年所创造的 Logo 编程语言。\n",
    "\n",
    "请想象绘图区有一只机器海龟，起始位置在 x-y 平面的 (0, 0) 点。先执行 `import turtle`，再执行 `turtle.forward(15)`，它将(在屏幕上)朝所面对的 x 轴正方向前进 15 像素，随着它的移动画出一条线段。再执行 `turtle.right(25)`，它将原地右转 25 度。\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "158b8a2a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import turtle as t\n",
    "import time\n",
    "\n",
    "t.color('red', 'red')\n",
    "t.begin_fill()\n",
    "for i in range(5):\n",
    "    t.fd(200)\n",
    "    t.rt(144)\n",
    "    time.sleep(1)\n",
    "t.end_fill()\n",
    "t.done()\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
